<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>relativeTimeThreshold() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>relativeTimeThreshold()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>relativeTimeThreshold()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/customization/relative-time-threshold/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/07-customization/13-relative-time-threshold.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment.relativeTimeThreshold(unit);  // getter
moment.relativeTimeThreshold(unit, limit);  // setter
</code></pre>

							</div>
<p><code>duration.humanize</code> &#x5177;&#x6709;&#x9608;&#x503C;&#xFF0C;&#x8FD9;&#x4E9B;&#x9608;&#x503C;&#x5B9A;&#x4E49;&#x4F55;&#x65F6;&#x5C06;&#x4E00;&#x4E2A;&#x5355;&#x4F4D;&#x89C6;&#x4E3A;&#x4E00;&#x5206;&#x949F;&#x3001;&#x4E00;&#x5C0F;&#x65F6;&#x7B49;&#x3002;
&#x4F8B;&#x5982;&#xFF0C;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8D85;&#x8FC7;45&#x79D2;&#x4F1A;&#x88AB;&#x89C6;&#x4E3A;&#x4E00;&#x5206;&#x949F;&#xFF0C;&#x8D85;&#x8FC7;22&#x5C0F;&#x65F6;&#x4F1A;&#x88AB;&#x89C6;&#x4E3A;&#x4E00;&#x5929;&#xFF0C;&#x4F9D;&#x6B64;&#x7C7B;&#x63A8;&#x3002;
&#x8981;&#x66F4;&#x6539;&#x8FD9;&#x4E9B;&#x622A;&#x6B62;&#x503C;&#xFF0C;&#x5219;&#x4F7F;&#x7528; <code>moment.relativeTimeThreshold(unit, limit)</code>&#xFF0C;&#x5176;&#x4E2D; unit &#x662F; <code>ss</code>&#x3001;<code>s</code>&#x3001;<code>m</code>&#x3001;<code>h</code>&#x3001;<code>d</code>&#x3001;<code>M</code> &#x4E4B;&#x4E00;&#x3002;</p>
<table>
  <tbody>
    <tr>
      <th>&#x5355;&#x4F4D;</th>
      <th>&#x542B;&#x4E49;</th>
      <th>&#x7528;&#x6CD5;</th>
    </tr>
    <tr>
      <td>ss</td>
      <td>&#x51E0;&#x79D2;&#x949F;</td>
      <td>&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x79D2;&#x949F;&#x7684;&#x6700;&#x5C11;&#x79D2;&#x6570;&#x3002;&#x5FC5;&#x987B;&#x5728;&#x8BBE;&#x7F6E; `s` &#x5355;&#x4F4D;&#x4E4B;&#x540E;&#x8BBE;&#x7F6E;&#xFF0C;&#x6216;&#x8005;&#x4E0D;&#x8BBE;&#x7F6E; `s` &#x5355;&#x4F4D;&#x3002;</td>
    </tr>
    <tr>
      <td>s</td>
      <td>&#x79D2;&#x949F;</td>
      <td>&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x4E00;&#x5206;&#x949F;&#x7684;&#x6700;&#x5C11;&#x79D2;&#x6570;&#x3002;</td>
    </tr>
    <tr>
      <td>m</td>
      <td>&#x5206;&#x949F;</td>
      <td>&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x4E00;&#x5C0F;&#x65F6;&#x7684;&#x6700;&#x5C11;&#x5206;&#x949F;&#x6570;&#x3002;</td>
    </tr>
    <tr>
      <td>h</td>
      <td>&#x5C0F;&#x65F6;</td>
      <td>&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x4E00;&#x5929;&#x7684;&#x6700;&#x5C11;&#x5C0F;&#x65F6;&#x6570;&#x3002;</td>
    </tr>
    <tr>
      <td>d</td>
      <td>&#x5929;</td>
      <td>&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x4E00;&#x4E2A;&#x6708;&#x7684;&#x6700;&#x5C11;&#x5929;&#x6570;&#x3002;</td>
    </tr>
    <tr>
      <td>M</td>
      <td>&#x6708;&#x4EFD;</td>
      <td>&#x88AB;&#x8BA4;&#x4E3A;&#x662F;&#x4E00;&#x5E74;&#x7684;&#x6700;&#x5C11;&#x6708;&#x4EFD;&#x6570;&#x3002;</td>
    </tr>
  </tbody>
</table>
<pre><code class="language-javascript">  // &#x68C0;&#x7D22;&#x73B0;&#x6709;&#x7684;&#x9608;&#x503C;&#x3002;
  moment.relativeTimeThreshold(&apos;ss&apos;); // 44
  moment.relativeTimeThreshold(&apos;s&apos;);  // 45
  moment.relativeTimeThreshold(&apos;m&apos;);  // 45
  moment.relativeTimeThreshold(&apos;h&apos;);  // 22
  moment.relativeTimeThreshold(&apos;d&apos;);  // 26
  moment.relativeTimeThreshold(&apos;M&apos;);  // 11

  // &#x8BBE;&#x7F6E;&#x65B0;&#x7684;&#x9608;&#x503C;&#x3002;
  moment.relativeTimeThreshold(&apos;ss&apos;, 3);
  moment.relativeTimeThreshold(&apos;s&apos;, 40);
  moment.relativeTimeThreshold(&apos;m&apos;, 40);
  moment.relativeTimeThreshold(&apos;h&apos;, 20);
  moment.relativeTimeThreshold(&apos;d&apos;, 25);
  moment.relativeTimeThreshold(&apos;M&apos;, 10);
</code></pre>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x68C0;&#x7D22;&#x9608;&#x503C;&#x65B0;&#x589E;&#x4E8E; <strong>2.8.1</strong>&#x3002;</p>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x68C0;&#x7D22;&#x4E0E;&#x8BBE;&#x7F6E; <code>ss</code> &#x9608;&#x503C;&#x65B0;&#x589E;&#x4E8E; <strong>2.18.0</strong>&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment.relativeTimeThreshold(unit);  // getter
moment.relativeTimeThreshold(unit, limit);  // setter
</code></pre>

							</div>
<p><code>duration.humanize</code> has thresholds which define when a unit is considered a minute, an hour and so on. For example, by default more than 45 seconds is considered a minute, more than 22 hours is considered a day and so on. To change those cutoffs use <code>moment.relativeTimeThreshold(unit, limit)</code> where unit is one of <code>ss</code>, <code>s</code>, <code>m</code>, <code>h</code>, <code>d</code>, <code>M</code>.</p>
<table>
  <tbody>
    <tr>
      <th>unit</th>
      <th>meaning</th>
      <th>usage</th>
    </tr>
    <tr>
      <td>ss</td>
      <td>a few seconds</td>
      <td>least number of seconds to be considered seconds. Must be set after setting the `s` unit or without setting the `s` unit.</td>
    </tr>
    <tr>
      <td>s</td>
      <td>seconds</td>
      <td>least number of seconds to be considered a minute.</td>
    </tr>
    <tr>
      <td>m</td>
      <td>minutes</td>
      <td>least number of minutes to be considered an hour.</td>
    </tr>
    <tr>
      <td>h</td>
      <td>hours</td>
      <td>least number of hours to be considered a day.</td>
    </tr>
    <tr>
      <td>d</td>
      <td>days</td>
      <td>least number of days to be considered a month.</td>
    </tr>
    <tr>
      <td>M</td>
      <td>months</td>
      <td>least number of months to be considered a year.</td>
    </tr>
  </tbody>
</table>
<pre><code class="language-javascript">  // Retrieve existing thresholds
  moment.relativeTimeThreshold(&apos;ss&apos;); // 44
  moment.relativeTimeThreshold(&apos;s&apos;);  // 45
  moment.relativeTimeThreshold(&apos;m&apos;);  // 45
  moment.relativeTimeThreshold(&apos;h&apos;);  // 22
  moment.relativeTimeThreshold(&apos;d&apos;);  // 26
  moment.relativeTimeThreshold(&apos;M&apos;);  // 11

  // Set new thresholds
  moment.relativeTimeThreshold(&apos;ss&apos;, 3);
  moment.relativeTimeThreshold(&apos;s&apos;, 40);
  moment.relativeTimeThreshold(&apos;m&apos;, 40);
  moment.relativeTimeThreshold(&apos;h&apos;, 20);
  moment.relativeTimeThreshold(&apos;d&apos;, 25);
  moment.relativeTimeThreshold(&apos;M&apos;, 10);
</code></pre>
<p><strong>Note:</strong> Retrieving thresholds was added in <strong>2.8.1</strong>.</p>
<p><strong>Note:</strong> Retrieving and setting <code>ss</code> threshold was added in <strong>2.18.0</strong>.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>